import store from '../store/index.js'

export default {
	onShow() {
		this.setTabBarBadge()
	},
	watch: {
		badgeSum() {
			this.setTabBarBadge()
		}
	},

	methods: {
		setTabBarBadge() {
			const pageArrLength = getCurrentPages().length
			if (pageArrLength <= 1) {
				if (store.getters['cart/allNum']) {
					uni.setTabBarBadge({
						index: 3,
						text: store.getters['cart/allNum'] + ''
					})
				} else {
					uni.removeTabBarBadge({
						index: 3
					})
				}
			}
		}
	},
	computed: {
		badgeSum() {
			return store.getters['cart/allNum'];
		}
	}
}